package com.example.winner.recyclerview;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
/**
 * Created by winner on 2018/6/6.
 */

public class Adapter extends RecyclerView.Adapter<Adapter.ViewHolder>{
    private List<ImageText> ImagetextList;
    static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView imageView;
        TextView textView;
        public ViewHolder(View view){
            super(view);
            imageView=(ImageView)view.findViewById ( R.id.image );
            textView=(TextView)view.findViewById ( R.id.text );
        }
    }
    public Adapter(List<ImageText>imagetextList)
    {
        ImagetextList=imagetextList;
    }

    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
        View view=LayoutInflater.from ( parent.getContext () )
                .inflate ( R.layout.item,parent,false );
        ViewHolder holder=new ViewHolder ( view );
        return holder;
    }
    public void onBindViewHolder(ViewHolder holder,int position)
    {
        ImageText imagetext=ImagetextList.get ( position );
        holder.imageView.setImageResource ( imagetext.getImageId () );
        holder.textView.setText ( imagetext.getText () );
    }
    public int getItemCount()
    {
        return ImagetextList.size ();
    }
}
